package com.hq.ims.platform.controller;

import com.hq.ims.data.annotation.DataRangeConcatenation;
import com.hq.ims.data.entityenum.EnumBusinessTypeStatus;
import com.hq.ims.data.service.other.BusiInfoStatisticsService;
import com.hq.ims.data.utils.LocalConstant;
import com.hq.ims.data.vo.statistics.PublishStatisticsSearchVo;
import com.hq.ims.data.vo.statistics.PublishStatisticsVo;
import com.hq.ims.data.vo.statistics.TrackStatisticsVo;
import com.hq.ims.data.vo.statistics.statisticsEnum.EnumDimension;
import com.hq.ims.platform.busservice.PlatformStatisticsService;
import com.hq.ims.platform.vo.PlatformStatisticsMapstruct;
import com.hq.utils.vo.ReturnVo;
import com.hq.web.annotations.GetJsonValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author yinzhangxiao
 * @date 2024/11/1 13:42
 * @ClassName PlatformStatisticsController
 **/
@Api(tags = "平台端经营信息统计")
@RestController
@RequestMapping(LocalConstant.SYS_TYPE_PLATFORM_URL_PREFIX + "/busiInfoStatistics")
public class PlatformStatisticsController {
    @Resource
    private BusiInfoStatisticsService busiInfoStatisticsService;
    @Resource
    private PlatformStatisticsService platformStatisticsService;

    @ApiOperation(value = "经营信息发布统计", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({})
    @PostMapping(value = "/pubulishStatistics", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<PublishStatisticsVo> pubulishStatistics(@RequestBody PublishStatisticsSearchVo searchVo) {
        //统计维度不传默认为天
        if (Objects.isNull(searchVo.getDimension())) {
            searchVo.setDimension(EnumDimension.Day);
        }
        //统计信息类型范围
        EnumBusinessTypeStatus[] infoType = {
                EnumBusinessTypeStatus.ProfessionRelevance,
                EnumBusinessTypeStatus.AllUserBusiness,
                EnumBusinessTypeStatus.BigData,
                EnumBusinessTypeStatus.ExternalStatement
        };
        searchVo.setInfoTypeList(Arrays.asList(infoType));
        return ReturnVo.buildSuccess(busiInfoStatisticsService.pubulishStatistics(searchVo));
    }

    @ApiOperation(value = "经营信息跟踪统计", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({})
    @PostMapping(value = "/trackStatistics", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<TrackStatisticsVo> trackStatistics(@GetJsonValue(zh = "组织Id", required = false) String orgId) {
        return ReturnVo.buildSuccess(busiInfoStatisticsService.trackStatistics(orgId));
    }

    @DataRangeConcatenation
    @ApiOperation(value = "平台端-公司发布信息统计", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/platformCompanyBusiCountDateStatistics", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<PlatformStatisticsMapstruct.CompanyBusiInfoCountStatisticsVo> platformCompanyBusiCountDateStatistics(
            @RequestBody PlatformStatisticsMapstruct.CompanyStatisticsSearchData searchData
    ) {
        return ReturnVo.buildSuccess(platformStatisticsService.platformCompanyInfoStatistics(searchData));
    }

    @ApiOperation(value = "平台端-公司收益信息统计", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/platformCompanyEarningsDateStatistics", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<PlatformStatisticsMapstruct.CompanyEarningsMoneyStatisticsVo>> platformCompanyEarningsDateStatistics(
            @RequestBody PlatformStatisticsMapstruct.CompanyStatisticsSearchData searchData
    ) {
        return ReturnVo.buildSuccess(platformStatisticsService.platformCompanyEarningsStatistics(searchData));
    }

    @ApiOperation(value = "平台端-公司个人收益信息统计", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/platformCompanyUserEarningsStatistics", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<PlatformStatisticsMapstruct.UserBusiInfoCountStatisticsVo>> platformCompanyUserEarningsStatistics(
            @RequestBody PlatformStatisticsMapstruct.CompanyUserStatisticsSearchData searchData
    ) {
        return ReturnVo.buildSuccess(platformStatisticsService.platformCompanyUserEarningsDateStatistics(searchData));
    }

}
